import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";

import VueRouter from "vue-router";

import less from "less";

import VueQuillEditor from "vue-quill-editor";

import "quill/dist/quill.core.css"; // import styles
import "quill/dist/quill.snow.css"; // for snow theme
import "quill/dist/quill.bubble.css"; // for bubble theme

import "assets/font/iconfont.css";
import "assets/css/base.css";

import axios from "axios";
axios.defaults.baseURL = "http://127.0.0.1:8999/api/private/v1/";
// axios请求拦截
axios.interceptors.request.use((config) => {
    // 为请求头对象，添加 Token 验证的 Authorization 字段
    config.headers.Authorization = window.sessionStorage.getItem("token");
    return config;
});
Vue.prototype.$request = axios;

// 解决重复路由报错
// 获取原型对象上的 push 函数
const originalPush = VueRouter.prototype.push;
// 修改原型对象中的 push 方法
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};

Vue.use(ElementUI);
Vue.use(less);
Vue.use(VueQuillEditor /* { default global options } */ );

Vue.filter("dateFormat", function(originVal) {
    let date = new Date(originVal);
    let year = date.getFullYear();
    let month = (date.getMonth() + 1 + "").padStart(2, "0");
    let day = (date.getDate() + "").padStart(2, "0");

    let hour = (date.getHours() + "").padStart(2, "0");
    let minute = (date.getMinutes() + 1 + "").padStart(2, "0");
    let second = (date.getSeconds() + "").padStart(2, "0");

    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
});

Vue.config.productionTip = false;
new Vue({
    router,
    store,
    render: (h) => h(App),
}).$mount("#app");